package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllUserActivitys", query = "select myUserActivity from UserActivity myUserActivity"),
		@NamedQuery(name = "findUserActivityByAction", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.action = ?1"),
		@NamedQuery(name = "findUserActivityByActionContaining", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.action like ?1"),
		@NamedQuery(name = "findUserActivityById", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.id = ?1"),
		@NamedQuery(name = "findUserActivityByLoggedDate", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.loggedDate = ?1"),
		@NamedQuery(name = "findUserActivityByPrimaryKey", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.id = ?1"),
		@NamedQuery(name = "findUserActivityByTagetRootType", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.tagetRootType = ?1"),
		@NamedQuery(name = "findUserActivityByTagetRootTypeContaining", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.tagetRootType like ?1"),
		@NamedQuery(name = "findUserActivityByTagetType", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.tagetType = ?1"),
		@NamedQuery(name = "findUserActivityByTagetTypeContaining", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.tagetType like ?1"),
		@NamedQuery(name = "findUserActivityByTargetId", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.targetId = ?1"),
		@NamedQuery(name = "findUserActivityByTargetRootId", query = "select myUserActivity from UserActivity myUserActivity where myUserActivity.targetRootId = ?1") })
@Table(catalog = "sow", name = "user_activity")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "UserActivity")
public class UserActivity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "ACTION", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String action;
	/**
	 */

	@Column(name = "TAGET_TYPE", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String tagetType;
	/**
	 */

	@Column(name = "TARGET_ID")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer targetId;
	/**
	 */

	@Column(name = "TAGET_ROOT_TYPE", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String tagetRootType;
	/**
	 */

	@Column(name = "TARGET_ROOT_ID")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer targetRootId;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LOGGED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar loggedDate;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "USER_ID", referencedColumnName = "ID") })
	@XmlTransient
	User user;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setAction(String action) {
		this.action = action;
	}

	/**
	 */
	public String getAction() {
		return this.action;
	}

	/**
	 */
	public void setTagetType(String tagetType) {
		this.tagetType = tagetType;
	}

	/**
	 */
	public String getTagetType() {
		return this.tagetType;
	}

	/**
	 */
	public void setTargetId(Integer targetId) {
		this.targetId = targetId;
	}

	/**
	 */
	public Integer getTargetId() {
		return this.targetId;
	}

	/**
	 */
	public void setTagetRootType(String tagetRootType) {
		this.tagetRootType = tagetRootType;
	}

	/**
	 */
	public String getTagetRootType() {
		return this.tagetRootType;
	}

	/**
	 */
	public void setTargetRootId(Integer targetRootId) {
		this.targetRootId = targetRootId;
	}

	/**
	 */
	public Integer getTargetRootId() {
		return this.targetRootId;
	}

	/**
	 */
	public void setLoggedDate(Calendar loggedDate) {
		this.loggedDate = loggedDate;
	}

	/**
	 */
	public Calendar getLoggedDate() {
		return this.loggedDate;
	}

	/**
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 */
	@JsonIgnore
	public User getUser() {
		return user;
	}

	/**
	 */
	public UserActivity() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(UserActivity that) {
		setId(that.getId());
		setAction(that.getAction());
		setTagetType(that.getTagetType());
		setTargetId(that.getTargetId());
		setTagetRootType(that.getTagetRootType());
		setTargetRootId(that.getTargetRootId());
		setLoggedDate(that.getLoggedDate());
		setUser(that.getUser());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("action=[").append(action).append("] ");
		buffer.append("tagetType=[").append(tagetType).append("] ");
		buffer.append("targetId=[").append(targetId).append("] ");
		buffer.append("tagetRootType=[").append(tagetRootType).append("] ");
		buffer.append("targetRootId=[").append(targetRootId).append("] ");
		buffer.append("loggedDate=[").append(loggedDate).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof UserActivity))
			return false;
		UserActivity equalCheck = (UserActivity) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
